#ifndef _ALLOCATOR_H
#define _ALLOCATOR_H

#include <stdint.h>
#include <string.h>
#include "Hardware.h"

//��Ҫʹ�����ṩ�����жϽӿ�
#define  OS_ENTER_CRITICAL()  Hardware_EnterCritical()//UART_ITConfig(UART1, UART_IT_RB, DISABLE)//__disable_irq();//
#define  OS_EXIT_CRITICAL()   Hardware_ExitCritical()//UART_ITConfig(UART1, UART_IT_RB, ENABLE)//__enable_irq();//

struct _CHN_SLOT
{
    uint16_t rx;      //��¼��ȡ���������ţ�bit15~bit5��������д���λ�ã�bit4~bit0��
    uint16_t tx;      //��¼д�뻺�������ţ�bit15~bit5��������д���λ�ã�bit4~bit0��
    uint16_t data_cnt;//��¼��������δ��ȡ��������
};


//1KB�ڴ��  16��
#define MAX_BUFFER_SZ           (MAX_POOL_SZ-BUFFER_NO_SZ)   //�ڴ�ؿ������ݴ�С
#define BUFFER_NO_SZ            (MAX_POOL_SZ>>BLK_NO_SHIFT)  //�ڴ�ؿ���Ŀ 16��
#define MAX_POOL_SZ             1024                         //�ڴ���ܴ�С 1024B

#define BLK_NO_SHIFT            6
#define BLK_SZ                  (0x01 << BLK_NO_SHIFT)      //���С
#define INVALID_BLK_NO          0xFF

#define INVALID_PTR             (INVALID_BLK_NO << BLK_NO_SHIFT)// 0001 1111 111    0 0000

struct _CHN_POOL_MGR//�ڴ��
{
    U8    buffer[MAX_POOL_SZ];
    uint16_t   free_bitmap; //1������   0��ʹ��
};

void init_chn_pool_mgr(void);
U8 put_chn_bytes(struct _CHN_SLOT *pCHN_SLOT, unsigned char buffer[], U8 len);
U8 get_chn_bytes(struct _CHN_SLOT *pCHN_SLOT, unsigned char buffer[], U8 len);
U8 peek_chn_bytes(struct _CHN_SLOT *pCHN_SLOT, unsigned char data[], U8 len);
void empty_a_chn_slot(struct _CHN_SLOT *pCHN_SLOT,  uint16_t len);

#endif
